package com.my.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * NIO channel4
 * @author Lelezhang
 * @create 2020-07-26 23:21
 */
public class NIOFileChannel4 {
    public static void main(String[] args) throws Exception {
        // 创建输入输出输出流
        FileInputStream fileInputStream = new FileInputStream("channel1.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("channel4.txt");
        // 获取channel
        FileChannel fileInputStreamChannel = fileInputStream.getChannel();
        FileChannel fileOutputStreamChannel = fileOutputStream.getChannel();
        // 使用transferFrom拷贝
        fileOutputStreamChannel.transferFrom(fileInputStreamChannel,0,fileInputStreamChannel.size());
        // 关闭流
        fileInputStreamChannel.close();
        fileOutputStreamChannel.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
